package com.hyperion.blog.controller;

import com.hyperion.blog.common.aop.LogAnnotation;
import com.hyperion.blog.service.SysUserService;
import com.hyperion.blog.vo.ErrorCode;
import com.hyperion.blog.vo.LoginUserVo;
import com.hyperion.blog.vo.result.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Hyperion
 */
@RestController
@RequestMapping("/users")
public class UserController {

    @Resource
    private SysUserService sysUserService;

    @GetMapping("/currentUser")
    @LogAnnotation(clazz = "UserController", method = "currentUser")
    public Result currentUser(@RequestHeader("Authorization") String token) {
        LoginUserVo loginUserVo = sysUserService.getUserInfoByToken(token);
        if (loginUserVo == null) {
            return Result.fail(ErrorCode.NO_LOGIN);
        }
        return Result.success(loginUserVo);
    }

}
